import asyncio
from re import U
import time
import aiohttp
from aiohttp import TCPConnector

# 获取当前时间戳的匿名函数
now = lambda: time.time()


# 协程函数: 请求url获取响应，然后打印响应的状态码
async def parse_url(url):
    async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(limit=64, verify_ssl=False)) as session:
        async with session.get(url) as resp:
            print(resp.text)


# 入口函数
async def run():
    url = ['http://www.ynhousedata.cn/house/assessment/assess_public?token=feed47c23e0b4c40d98931aa4f2652af&timestamp=2022-04-26 16:20:33&layer=1&total_layer=8&total_area=120&pre_id=4450',
           'http://www.ynhousedata.cn/house/assessment/assess_public?token=feed47c23e0b4c40d98931aa4f2652af&timestamp=2022-04-26 16:20:33&layer=1&total_layer=8&total_area=120&pre_id=4450https://km.ke.com/xiaoqu/4320024554870426/',
           'http://www.ynhousedata.cn/house/assessment/assess_public?token=feed47c23e0b4c40d98931aa4f2652af&timestamp=2022-04-26 16:20:33&layer=1&total_layer=8&total_area=120&pre_id=4450',
           'http://www.ynhousedata.cn/house/assessment/assess_public?token=feed47c23e0b4c40d98931aa4f2652af&timestamp=2022-04-26 16:20:33&layer=1&total_layer=8&total_area=120&pre_id=4450',
           'http://www.ynhousedata.cn/house/assessment/assess_public?token=feed47c23e0b4c40d98931aa4f2652af&timestamp=2022-04-26 16:20:33&layer=1&total_layer=8&total_area=120&pre_id=4450',
           ]
    # 将多个协程任务 装进 tasks任务列表中
    tasks = [parse_url(x) for x in url]
    await asyncio.wait(tasks)


if __name__ == '__main__':
    start_time = now()
    loop = asyncio.get_event_loop()
    loop.run_until_complete(run())
    print(f"耗时: {now() - start_time}")
